#include <iostream>
using std::cout;
using std::endl;

void print(int x){
    cout << "print:" << x << endl;
}

void display(int x){
    cout << "display:" << x << endl;
}

class FFF
{
public:
    void print(int x){
        cout << "FFF::print:" << x << endl;
    }

    void display(int x){
        cout << "FFF::display:" << x << endl;
    }

    static void show(int x){
        cout << "FFF::show:" << x << endl;
    }
};

class DDD
{
public:
    void print(int x){
        cout << "DDD::print:" << x << endl;
    }
};


typedef void (*Function)(int);
typedef void (FFF::*MemFunction)(int);

void test0(){
    Function p1;
    p1 = FFF::show;
    p1(6);

    /* Function p2 = FFF::print;//error */
    /* void (FFF::*p3)(int) = &DDD::print; */

    //成员函数指针定义时要确定其指向的成员函数的
    //类、返回类型、参数信息
    void (FFF::*p2)(int) = &FFF::print;
    void (FFF::*p3)(int) = &FFF::display;
    MemFunction p4;
    p4 = &FFF::print;
    
    FFF fff;
    //.*成员指针运算符的形式之一
    (fff.*p4)(3);

    FFF * fp = new FFF();
    /* fp->print(2); */

    //->*成员指针运算符的形式之二
    (fp->*p4)(7);

    //关于空指针的使用，作为了解
    delete fp;
    fp = nullptr;

    fp->print(2);
    (fp->*p4)(7);
}

void test1(){
    void (*p1)(int) = print;
    p1(3);
    p1 = display;
    p1(5);

    Function p3;
    p3 = print;
    p3(2);
    p3 = display;
    p3(4);
}

int main(void){
    test0();
    return 0;
}
